package com.ptu.controller.user;

import com.ptu.server.SeckillOrderServer;
import com.ptu.util.Result;
import com.ptu.vo.SeckillOrderVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userSeckillOrderController")
@Tag(name = "秒杀订单模块")
@RequestMapping("/seckillOrder")
public class SeckillOrderController {

    @Autowired
    private SeckillOrderServer seckillOrderServer;

    @Operation(summary = "获取秒杀订单列表")
    @RequestMapping("/list")
    public List<SeckillOrderVO> list() {
        return seckillOrderServer.list();
    }


    @Operation(summary = "用户秒杀下单")
    @RequestMapping("/add/{productId}")
    public Result<Void> add(@PathVariable Long productId) {
        return seckillOrderServer.add(productId);
    }

    @Operation(summary = "用户支付订单")
    @RequestMapping("/pay/{id}")
    public Result<Void> pay(@PathVariable Long id) {
        seckillOrderServer.pay(id);
        return Result.success();
    }

    @Operation(summary = "用户取消订单")
    @RequestMapping("/cancel/{id}")
    public Result<Void> cancel(@PathVariable Long id) {
        seckillOrderServer.cancel(id);
        return Result.success();
    }

    @Operation(summary = "用户申请退款")
    @RequestMapping("/refund/{id}")
    public Result<Void> refund(@PathVariable Long id) {
        seckillOrderServer.refund(id);
        return Result.success();
    }

    @Operation(summary = "用户完成订单")
    @RequestMapping("/complete/{id}")
    public Result<Void> complete(@PathVariable Long id) {
        seckillOrderServer.complete(id);
        return Result.success();
    }
}
